package cn.edu.nit.sys.mapper;

import cn.edu.nit.sys.entity.Approve;
import cn.edu.nit.sys.entity.Leave;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author xiaobai
 * @Date 2023/3/19 20:39
 * @Version 1.0.0
 */
@Mapper
public interface LeaveMapper extends BaseMapper<Leave> {

    Page<Leave> getLeaveList(Page<Leave> page, String uid);

    @Select("select id, flow_id, node, auditor_id, auditor, result, opinion, create_time from sys_approve where flow_id = #{flowId}" +
            " order by create_time")
    List<Approve> getApprove(String flowId);

    @Insert("insert into sys_approve(id, flow_id, node, result) values(#{id}, #{flowId}, '0', '1')")
    int insertApprove(String id, String flowId);

    @Select("select id, name, type, day, reason, flow, user_id, imgs, leave_type, create_time from sys_leave where id = #{id}")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "id", property = "approveList", one = @One(select = "getApprove"))
    })
    Leave getDetail(String id);
}
